﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Communication
{
    /// <summary>
    /// 光电检测控制
    /// </summary>
    public class DetectControl:ControlBase
    {
        string mJC1 = "MB1",//复位
            mJC2 = "MB2",//取条
            mJC3 = "MB3",//定位
            mJC4 = "MB4",//检测
            mJC5 = "MB5",//丢弃
            mJC6 = "MB6",//吸废液放针
            mJC7 = "MB7",//吸废液收针
            mQZ = "QZ",//检测光强
            mJC8="MB8";
        public DetectControl()
        {
            mCanId = Can.DETECT_HOUSE_ID;
            mSCmd = new Dictionary<int, string>();
            mSCmd.Add(0, mJC1);
            mSCmd.Add(1, mJC2);
            mSCmd.Add(2, mJC3);
            mSCmd.Add(3, mJC4);
            mSCmd.Add(4, mJC5);
            mSCmd.Add(5, mJC6);
            mSCmd.Add(6,mJC7);
            mSCmd.Add(7,mQZ);
            mSCmd.Add(8,mJC8);
        }
        /// <summary>
        /// 复位
        /// </summary>
        /// <returns>0</returns>
        public int Reset()
        {
            SendCmd(0,mJC1);
            mStatus = -100;
            return 0;
        }
        /// <summary>
        /// 到孵育
        /// </summary>
        /// <returns></returns>
        public int GoIncubation()
        {
            SendCmd(1,mJC2);
            mStatus = -1;
            return 1;
        }
        /// <summary>
        /// 定位检测条
        /// </summary>
        /// <returns></returns>
        public int PositionStrip()
        {
            SendCmd(2,mJC3);
            mStatus = -2;
            return 2;
        }
        /// <summary>
        /// 定位检测杯
        /// </summary>
        /// <returns></returns>
        public int PositionCup()
        {
            SendCmd(3,mJC4);
            mStatus = -3;
            return 3;
        }
        /// <summary>
        /// 直接丢弃反应条
        /// </summary>
        /// <returns></returns>
        public int ThrowStrip()
        {
            SendCmd(4,mJC5);
            mStatus = -4;
            return 4;
        }
        /// <summary>
        /// 吸废液2次
        /// </summary>
        public void Imbibe()
        {
            ImbibeStart();
            WaitStatus(5);
            ValveOpen(true);
            ImbibeEnd();
            WaitStatus(6);

            ImbibeStart();
            WaitStatus(5);
            ValveOpen(true);
            ImbibeEnd();
            WaitStatus(6);
        }
        /// <summary>
        /// 吸废液开始
        /// </summary>
        /// <returns></returns>
        public int ImbibeStart()
        {
           
            SendCmd(5,mJC6);
            mStatus = -5;
            return 5;
        }
        public int ImbibeEnd()
        {
            ValveOpen(false);
            SendCmd(6, mJC7);
            mStatus = -6;
            return 6;
        }
        /// <summary>
        /// 吸废液阀开关
        /// </summary>
        public void ValveOpen(bool open)
        {
            if (open)
            {
                Can.SendCan(Can.IO_CanID, "MA23" + Can.strEnd);
                Thread.Sleep(2000);
            }
            else
                Can.SendCan(Can.IO_CanID, "MW23" + Can.strEnd);
        }
        /// <summary>
        /// 只检测光强
        /// </summary>
        /// <returns></returns>
        public int OnlyDetect()
        {
            Can.SendCan(Can.DetectLight_ID, mQZ + Can.strEnd);
            mStatus = -7;
            return 7;
        }
        /// <summary>
        /// 抬起探头
        /// </summary>
        /// <returns></returns>
        public int UpDetector()
        {
            SendCmd(8, mJC8);
            Status = -8;
            return 8;
        }

    }
}
